<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StoreController
 *
 * @author taoheping 中
 */
class StoreController extends Uuch_BaseController {

    public function homeAction() {

        $this->appendCss('/css/storage.css');

        $this->setTitle('个人云仓库 | 免费仓库 | 国内免费仓储');

        $this->appendScript('/js/jquery.min.js')
                ->appendScript('/js/jquery.validate.min.js')
                ->appendScript('/js/messages_cn.js');
        $words = array();
        for ($i = 0; $i < 26; $i++) {
            $words [] = chr(65 + $i);
        }
        $this->view->words = $words;
    }

    public function expressAction() {
        $this->appendCss('/css/express.css');
        $this->setTitle('悠奇国际速递 | 国际快递 | DHL UPS FedEx EMS 联邦快递');

        $this->appendScript('/js/jquery.min.js')
                ->appendScript('/js/jquery.validate.min.js')
                ->appendScript('/js/messages_cn.js');
        $words = array();
        for ($i = 0; $i < 26; $i++) {
            $words [] = chr(65 + $i);
        }
        $this->view->words = $words;
    }
    
    public function upAction(){
        $this->appendCss('/css/pickupservice.css');
        $this->appendScript('/js/jquery.min.js');
        $this->setTitle('上门取件');
    }

    public function visitingAction() {
        $this->appendCss('/css/express.css');
        $this->setTitle('悠奇上门取件');

        $this->appendScript('/js/jquery.min.js')
                ->appendScript('/js/jquery.validate.min.js')
                ->appendScript('/js/messages_cn.js');

        $visitingId = $this->getSafeParam("id");
        $userId = $this->currentUser()->Id;
        if ("" == $userId || null == $userId) {
            $this->checkLogin();
            return;
        }
        $cityItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultCity, null);
        $townItem = Application_Model_city::GetByParentId(Application_Model_city::ParentDefaultTown, null);
        $addressItem = Application_Model_address::getByUserIdType($userId, 1);
        $priceItem = Application_Model_ExpressPrice::getPriceByExpressAndCity(8, $townItem[0]["id"]);

        $this->view->addressAll = $addressItem;
        $this->view->price = $priceItem;
        $this->view->cityAll = $cityItem;
        $this->view->townAll = $townItem;
        $this->_helper->layout->disableLayout();
    }

    public function newaddressAction() {
        $userid = $this->currentUser()->id;
        $cityId = $this->getSafeParam("cityId");
        $townId = $this->getSafeParam("townId");
        $addressId = $this->getSafeParam("addressId");
        if ($addressId != "") {
            $newItem = Application_Model_address::load($addressId);
            if (!$newItem) {
                $newItem = new Application_Model_address();
            }
        } else {
            $newItem = new Application_Model_address();
        }
        if($cityId != "" && $cityId != 0 && $townId != "" && $townId != 0 && $this->getSafeParam("street") != "" && $this->getSafeParam("linkMan") != "" && $this->getSafeParam("mobile") != "")
        {
            $newItem->state = Application_Model_city::ParentDefaultCity; //所在国家
            $newItem->province = (int) ($cityId);
            $newItem->city = (int) ($townId);
            $newItem->street = $this->getSafeParam("street");
            $newItem->linkMan = $this->getSafeParam("linkMan");
            $newItem->mobile = $this->getSafeParam("mobile");
            $newItem->userId = $userid;
            $newItem->default = time();
            $newItem->comment = "";
            $newItem->type = (int) (Application_Model_address::Type_Inland);
            $newItem->save();
            $this->json($newItem->id);
        }else{
            $this->json(0);
        }
    }

    public function addressdetailAction() {
        $addressId = $this->getSafeParam("addressId");
        $addressItem = Application_Model_address::load($addressId);
        if ($addressItem != null) {
            $cityItem = Application_Model_city::load($addressItem->province);
            $townItem = Application_Model_city::load($addressItem->city);
            $this->json(array("type" => 1, "addressId" => $addressItem->id, "linkMan" => $addressItem->linkMan, "cityId" => $addressItem->province, "cityName" => $cityItem->name, "townId" => $addressItem->city, "townName" => $townItem->name, "street" => $addressItem->street, "mobile" => $addressItem->mobile));
        } else {
            $this->json(array("type" => 0));
        }
    }

    public function deladdressAction() {
        $addressId = $this->getSafeParam("addressId");
        $addressItem = Application_Model_address::load($addressId);
        if ($addressItem != null) {
            $addressItem->delete();
            $countItem = Application_Model_address::getByUserIdType($addressItem->userId, Application_Model_address::Type_Inland);
            $this->json(array("status" => 1, "num" => count($countItem)));
        } else {
            $this->json(array("status" => 0));
        }
    }

    public function citysubtownAction() {
        $cityId = $this->getSafeParam("cityid");
        $townItem = Application_Model_city::GetByParentId($cityId, null);
        $this->json(array("arrtown" => $townItem));
    }

    public function visitingsubmitAction() {
        $userId = $this->currentUser()->Id;
        if (!$userId)
            $this->checkLogin();
        $waresName = $this->getSafeParam("waresName");
        $waresDescribe = $this->getSafeParam("waresDescribe");
        $estimateWeight = $this->getSafeParam("estimateWeight");
        $estimateWeight = $estimateWeight * 1000;
        $length = $this->getSafeParam("length");
        $length = $length ? $length : 0;
        $width = $this->getSafeParam("width");
        $width = $width ? $width : 0;
        $height = $this->getSafeParam("height");
        $height = $height ? $height : 0;
        $estimateVolume = (int) ($length * $width * $height / 6);
        $addressId = $this->getSafeParam("addressId");
        $isWay = $this->getSafeParam("isWay");
        $inlandMoney = $this->getSafeParam("inlandMoney");
        $shipType = $this->getSafeParam("shipType");
        $itemType = "";
        if (is_array($this->_getParam('itemType'))) {
            foreach ($this->_getParam('itemType') as $type) {
                $itemType = $itemType | intval($type);
            }
        } else {
            $itemType = $this->_getParam('itemType');
        }
        $itemType = ($itemType == "" || $itemType == NULL) ? 0 : $itemType;
        $packageSize = $length . "*" . $width . "*" . $height;
        if ($waresName != "" && $isWay != "" && $addressId != "" && $shipType != "" && $waresDescribe != "") {
            $addressItem = Application_Model_address::load($addressId);
            $priceItem = Application_Model_ExpressPrice::getPriceByExpressAndCity($shipType, $addressItem->city);
            if ($priceItem) {
                $weight = $estimateWeight > $estimateVolume ? $estimateWeight : $estimateVolume;
                $inlandMoney = $priceItem->getMoneyByweight($weight);
            }
            $visitingItem = new Application_Model_VisitingServer();
            $visitingItem->visitingNo = Uuch_Util::getVisitingNumber($userId);
            $visitingItem->dateCreated = date("Y-m-d H:i:s");
            $visitingItem->userId = $userId;
            $visitingItem->waresName = $waresName;
            $visitingItem->estimateWeight = $estimateWeight;
            $visitingItem->estimateVolume = $estimateVolume;
            $visitingItem->inlandUser = $addressItem->linkMan;
            $visitingItem->inlandPhone = $addressItem->mobile;
            $visitingItem->inlandCityId = $addressItem->province;
            $visitingItem->inlandTownId = $addressItem->city;
            $visitingItem->inlandAddress = $addressItem->street;
            $visitingItem->inlandMoney = $inlandMoney;
            $visitingItem->guaranteeFee = 100; //100押金
            $visitingItem->inlandShipType = $shipType;
            $visitingItem->isWay = $isWay;
            $visitingItem->status = Application_Model_VisitingServer::STATUS_WaitPay;
            $visitingItem->interior = Application_Model_VisitingServer::Interior_WaitPay;
            $visitingItem->isDel = 0;
            $visitingItem->packageSize = $packageSize;
            $visitingItem->itemType = $itemType;
            $visitingItem->waresDescribe = $waresDescribe;
//            var_dump($visitingItem);exit;
            if ($visitingItem->isWay == 1) {
                $this->redirect('visitingway', 'store', array("adid" => $addressItem->id, "waresName" => $waresName, "waresDescribe" => $waresDescribe, "estimateWeight" => $estimateWeight, "estimateVolume" => $estimateVolume, "inlandShipType" => $shipType, "inlandMoney" => $inlandMoney, "packageSize" => $packageSize, "itemType" => $itemType));
            } else {
                $visitingItem->save();
                $this->redirect('paying', 'pay', array('type' => Application_Model_PayBill::TYPE_Visiting, 'id' => $visitingItem->Id));
            }
        } else {
            $this->redirect('visiting', 'store');
        }
    }

    /**
     * 上门取件直发海外
     */
    public function visitingwayAction() {
        $this->appendCss('/css/express.css');
        $this->appendCss('/css/home/order.css');
        $this->appendScript('/js/jquery.min.js')
                ->appendScript('/js/jquery.validate.min.js')
                ->appendScript('/js/messages_cn.js');
        $this->setTitle('上门取件直发海外');
        $userId = $this->currentUser()->Id;
        if (!$userId)
            $this->checkLogin();
        $waresName = $this->getSafeParam("waresName");
        $waresDescribe = $this->getSafeParam("waresDescribe");
        $estimateWeight = $this->getSafeParam("estimateWeight");
        $estimateWeight = $estimateWeight * 1000;
        $length = $this->getSafeParam("length");
        $length = $length ? $length : 0;
        $width = $this->getSafeParam("width");
        $width = $width ? $width : 0;
        $height = $this->getSafeParam("height");
        $height = $height ? $height : 0;
        $estimateVolume = (int) ($length * $width * $height / 5);
        $addressId = $this->getSafeParam("addressId");
        $isWay = $this->getSafeParam("isWay");
        $inlandMoney = $this->getSafeParam("inlandMoney");
        $shipType = $this->getSafeParam("shipType");
        $itemType = "";
        if (is_array($this->_getParam('itemType'))) {
            foreach ($this->_getParam('itemType') as $type) {
                $itemType = $itemType | intval($type);
            }
        } else {
            $itemType = $this->_getParam('itemType');
        }
        $itemType = ($itemType == "" || $itemType == NULL) ? 0 : $itemType;
        $packageSize = $length . "*" . $width . "*" . $height;
        if ($waresName != "" && $isWay != "" && $addressId != "" && $shipType != "" && $waresDescribe != "") {
            if ($isWay == 0) {
                $addressItem = Application_Model_address::load($addressId);
                $priceItem = Application_Model_ExpressPrice::getPriceByExpressAndCity($shipType, $addressItem->city);
                if ($priceItem) {
                    $weight = $estimateWeight > $estimateVolume ? $estimateWeight : $estimateVolume;
                    $inlandMoney = $priceItem->getMoneyByweight($weight);
                }
                $visitingItem = new Application_Model_VisitingServer();
                $visitingItem->visitingNo = Uuch_Util::getVisitingNumber($userId);
                $visitingItem->dateCreated = date("Y-m-d H:i:s");
                $visitingItem->userId = $userId;
                $visitingItem->waresName = $waresName;
                $visitingItem->estimateWeight = $estimateWeight;
                $visitingItem->estimateVolume = $estimateVolume;
                $visitingItem->inlandUser = $addressItem->linkMan;
                $visitingItem->inlandPhone = $addressItem->mobile;
                $visitingItem->inlandCityId = $addressItem->province;
                $visitingItem->inlandTownId = $addressItem->city;
                $visitingItem->inlandAddress = $addressItem->street;
                $visitingItem->inlandMoney = $inlandMoney;
                $visitingItem->guaranteeFee = 100; //100押金
                $visitingItem->inlandShipType = $shipType;
                $visitingItem->isWay = $isWay;
                $visitingItem->status = Application_Model_VisitingServer::STATUS_WaitPay;
                $visitingItem->interior = Application_Model_VisitingServer::Interior_WaitPay;
                $visitingItem->isDel = 0;
                $visitingItem->packageSize = $packageSize;
                $visitingItem->itemType = $itemType;
                $visitingItem->waresDescribe = $waresDescribe;
                $visitingItem->save();
                $countItem = Application_Model_VisitingServer::getCountByUserId($userId);
                if($countItem == 1){
                    $accountItem = Application_Model_UserAccount::addAccount($userId);
                    $accountItem->TaskExchangeScore(Application_Model_Task::TASK_VISITING);
                }
                $this->redirect('paying', 'pay', array('type' => Application_Model_PayBill::TYPE_Visiting, 'id' => $visitingItem->Id));
            }
        } else {
            $this->redirect('visiting', 'store');
        }


        $this->view->cnAddress = Application_Model_address::load($addressId);
        $this->view->waresName = $waresName;
        $this->view->waresDescribe = $waresDescribe;
        $this->view->weight = $estimateWeight;
        $this->view->bagWeight = Uuch_Util::getPackage($estimateWeight);
        $this->view->SumWeight = $this->view->bagWeight + $this->view->weight;
        $this->view->volumeWeight = $estimateVolume;
        $this->view->jsWeight = $this->view->SumWeight > $this->view->volumeWeight ? $this->view->SumWeight : $this->view->volumeWeight;
        $this->view->inlandShipType = $shipType;
        $this->view->inlandShipItem = Application_Model_Express::load($shipType);
        $this->view->inlandMoney = $inlandMoney;
        $this->view->packageSize = $packageSize;
        $this->view->itemType = $itemType;
        $this->view->typeName = Application_Model_StoreItem::getNames();
        $address = Application_Model_address::getByUserIdType($userId);
        $this->view->address = array_reverse(Uuch_Util::quickSort($address, 'Id'));
        $isEast = FALSE;
        if (count($address) == 0) {
            $this->view->default = new Application_Model_address(array('State' => 1));
            $this->view->hasAddress = false;
            $this->view->isEuro = FALSE;
        } else {
            $this->view->default = $address[count($address) - 1];
            $city = $this->view->default->getCityBy();
            $this->view->isEuro = ($city->AreaCode >= 7 && $city->AreaCode <= 10);
            $this->view->hasAddress = TRUE;
            $this->view->isZipRemoteFee = Application_Model_RemoteFee::byStateIdZip($this->view->default->State, $this->view->default->Postcode);
            if($this->view->default->State == Application_Model_city::Malaysia){
                $isEast = Application_Model_RemoteFee::EastOrWestern($this->view->default->Postcode);
            }
        }
        $this->view->prices = Application_Model_Express::getPricesByCity($this->view->default->State);
        $words = array();
        for ($i = 0; $i < 26; $i++) {
            $words [] = chr(65 + $i);
        }

        $this->view->words = $words;
        $this->view->coupons = Application_Model_Coupon::getByUser($userId, Application_Model_Coupon::STATUS_OK);
        $this->view->isEast = $isEast;
        $this->_helper->layout->disableLayout();
    }

    public function calculatemoneyAction() {
        $addressId = $this->getSafeParam("addressId");
        $weight = $this->getSafeParam("weight");
        $shipId = $this->getSafeParam("shipId");
        $addressItem = Application_Model_address::load($addressId);
        if ($addressItem != null) {
            $priceItem = Application_Model_ExpressPrice::getPriceByExpressAndCity($shipId, $addressItem->city);
            if ($priceItem) {
                $money = $priceItem->getMoneyByweight($weight * 1000);
                $this->json(array("status" => 1, "money" => $money));
            } else {
                $this->json(array("status" => 0));
            }
        } else {
            $this->json(array("status" => 0));
        }
    }

    public function newforeignaddressAction() {
        $userid = $this->currentUser()->id;
        $newItem = new Application_Model_address();
        $newItem->state = $this->getSafeParam("state"); //所在国家
        //$newItem->province=$this->getSafeParam("province");
        //$newItem->city=$this->getSafeParam("City");
        $newItem->street = $this->getSafeParam("street");
        $newItem->comment = "";
        $newItem->postcode = $this->getSafeParam("postCode");
        $newItem->linkMan = $this->getSafeParam("linkMan");
        $newItem->mobile = $this->getSafeParam("mobile");
        //$newItem->phone=$this->getSafeParam("phone");
        $newItem->userId = $userid;
        $newItem->default = time(); //默认值
        $newItem->type = Application_Model_address::Type_Foreign;
        $newItem->save();
        $this->view->newAddressId = $newItem->Id;
        $weight = $this->getSafeParam("weight");
        $volumeWeight = $this->getSafeParam("volumeWeight");
        $itemType = $this->getSafeParam("itemType");
        $this->setcultfee($newItem->Id, $weight, $volumeWeight, $itemType);
        $this->render('cultfee');
    }

    public function cultfeeAction() {
        $addressId = $this->getSafeParam('address');
        $weight = $this->getSafeParam("weight");
        $volumeWeight = $this->getSafeParam("volumeWeight");
        $itemType = $this->getSafeParam("itemType");
        $this->setcultfee($addressId, $weight, $volumeWeight, $itemType);
    }

    private function setcultfee($addressId, $weight, $volumeWeight, $itemType) {
        $address = Application_Model_address::load($addressId);
        $this->view->SumWeight = $weight;
        $this->view->volumeWeight = $volumeWeight;
        $this->view->itemType = $itemType;
        $this->view->city = $address->getCityBy();
        $this->view->typeName = Application_Model_StoreItem::getNames();
        $this->view->prices = Application_Model_ExpressPrice::getPricesByCity($address->State);
        $this->view->isZipRemoteFee = Application_Model_RemoteFee::byStateIdZip($address->State, $address->Postcode);
        $isEast = FALSE;
        if($address->State == Application_Model_city::Malaysia){
            $isEast = Application_Model_RemoteFee::EastOrWestern($address->Postcode);
        }
        $this->view->isEast = $isEast;
        $this->_helper->layout->disableLayout();
    }

    public function vswaysubmitAction() {
//        $post = $this->_getAllParams();
//        var_dump($post);exit;
        $userId = $this->currentUser()->id;
        $adId = $this->getSafeParam("adid");
        $addressItem = Application_Model_address::load($adId);
        $inlandShipType = $this->getSafeParam("inlandShipType");
        $waresName = $this->getSafeParam("waresName");
        $waresDescribe = $this->getSafeParam("waresDescribe");
        $productWeight = $this->getSafeParam("weight");
        $volumeWeight = $this->getSafeParam("volumeWeight");
        $inlandMoney = $this->getSafeParam("inlandMoney");
        $packageSize = $this->getSafeParam("packageSize");
        $visitingItem = new Application_Model_VisitingServer();
        $visitingItem->visitingNo = Uuch_Util::getVisitingNumber($userId);
        $visitingItem->dateCreated = date("Y-m-d H:i:s");
        $visitingItem->userId = $userId;
        $visitingItem->waresName = $waresName;
        $visitingItem->waresDescribe = $waresDescribe;
        $visitingItem->estimateWeight = $productWeight;
        $visitingItem->estimateVolume = $volumeWeight;
        $visitingItem->inlandUser = $addressItem->linkMan;
        $visitingItem->inlandPhone = $addressItem->mobile;
        $visitingItem->inlandCityId = $addressItem->province;
        $visitingItem->inlandTownId = $addressItem->city;
        $visitingItem->inlandAddress = $addressItem->street;
        $visitingItem->inlandMoney = $inlandMoney; //国内费用
        $visitingItem->guaranteeFee = 100; //100押金
        $visitingItem->inlandShipType = $inlandShipType;
        $visitingItem->packageSize = $packageSize;
        $visitingItem->isWay = 1;
        $visitingItem->status = Application_Model_VisitingServer::STATUS_WaitPay;
        $visitingItem->interior = Application_Model_VisitingServer::Interior_WaitPay;
        $visitingItem->isDel = 0;


        $shipType = $this->getSafeParam("shipType");
        $ship = Application_Model_Express::load($shipType);


        $bagWeight = Uuch_Util::getPackage($productWeight);

        $weight = 0;
        $isVolume = FALSE;
        if ($ship->IsVolume && $volumeWeight > $productWeight + $bagWeight) {
            $weight = $volumeWeight;
            $isVolume = TRUE;
        } else {
            $weight = $productWeight + $bagWeight;
        }

        $addressId = $this->getSafeParam('addressId');
        $address = Application_Model_address::load($addressId);

        $ep = Application_Model_ExpressPrice::getPriceByExpressAndCity($ship->Id, $address->State);
        $shipFee = $ep->getMoneyByweight($weight);

        //$shipMoney = Application_Model_shipFeeConfig::getMoney($address->State, $ship->Id, $weight);
//        $couponNo = $this->getSafeParam('couponno');
//        $password = $this->getSafeParam('password');
        $discount = 0;
//        $coupon = NULL;
//        if ($couponNo != '0') {
//            $coupon = Application_Model_Coupon::getByNo($couponNo);
//            $couponResult = $coupon->Validate($userId, $shipFee, $password);
//            if($couponResult->result){
//                $discount = $couponResult->discount;
//                $coupon->Status = Application_Model_Coupon::STATUS_USED;
//            }
//        }
        
        //偏远费
        $foRemoteFee = 0;
        $isRemoteFee = Application_Model_RemoteFee::byStateIdZip($address->State, $address->Postcode);
        if($isRemoteFee && $ship->IsRemoteFee){
            $foRemoteFee = Application_Model_RemoteFee::remoteFee;;
        }
        
        $serviceFee = 0; //暂时不收服务费
        $woodenFee = $this->getSafeParam('isWooden') ? 50 : 0;
        $compressFee = $this->getSafeParam('isCompress') ? 20 : 0;
        $removalFee = $this->getSafeParam('isNoLogo')?20:0;
        $premiumFee = 0;
        $premiumValue = 0;
        if ($this->getSafeParam('isPremium') == '1') {
            $premiumValue = $this->getSafeParam('PremiumValue');
            if ($premiumValue != '') {
                $premiumFee = $premiumValue * Application_Model_Config::getPremiumRate()->Value;
            }
        }
        $shipMoney = $shipFee - $discount + $ship->ReportFee + $serviceFee + $inlandMoney + $woodenFee + $compressFee + $removalFee + $premiumFee + $foRemoteFee;
        if ($shipMoney < 0)
            $shipMoney = 0;

        $newItem = new Application_Model_wayBillItem();
        $wayCode = Uuch_Util::getWayCode();
        $newItem->billNo = $wayCode; //运单号
        $newItem->dateCreated = date('Y-m-d H:i:s'); //创建日期
        $newItem->status = Application_Model_wayBillItem::STATUS_Launch; //状态 未启用；
        $newItem->userId = $userId; //用户ID
        $newItem->interior = Application_Model_wayBillItem::STATUS_Launch;
        $newItem->lastdate = $this->now();
        $newItem->IsVolume = $isVolume;
        $newItem->setAllWeight($weight, $bagWeight, $productWeight, $volumeWeight);

        $newItem->shipType = $ship->Id; //运送方式
        $newItem->ExpressId = $ship->Id;
        $newItem->shipFeeconfig = $ep->Id;
        $newItem->setAddress($address);

        $newItem->isNoLogo = $this->getSafeParam('isNoLogo') ? '1' : '0'; //是否去掉吊牌，Logo等
        $newItem->isNoSkin = $this->getSafeParam('isNoSkin') ? '1' : '0'; //是否要去掉不必要包装
        $newItem->isCompress = $this->getSafeParam('isCompress') ? '1' : '0'; //是否要压缩抽气
        $newItem->isWooden = $this->getSafeParam('isWooden') ? '1' : '0';

        $newItem->dutyNo = $this->getSafeParam('dutyNo'); //税号

        $newItem->Remark = $this->getSafeParam('remark');

        $newItem->setAllMoney($shipMoney, $shipFee, $ship->ReportFee, $discount, $serviceFee);
        $newItem->save();

        $visitingItem->wayId = $newItem->Id;
        $visitingItem->isWayMoney = 1;
        $visitingItem->advanceMoney = $shipMoney;
        $visitingItem->save();
        $countItem = Application_Model_VisitingServer::getCountByUserId($userId);
        if($countItem == 1){
            $accountItem = Application_Model_UserAccount::addAccount($userId);
            $accountItem->TaskExchangeScore(Application_Model_Task::TASK_VISITING);
        }
//        if ($couponNo != '0' && $discount>0) {
//            $coupon->Relevance = $newItem->Id;
//            $coupon->UseTime = $this->now();
//            $coupon->save();
//        }
        //添加费用信息
        $newItem->addFee(Application_Model_FeeType::EstimateShipFee, $shipFee);
        $newItem->addFee(Application_Model_FeeType::CnShipFee, $inlandMoney);
        $newItem->addFee(Application_Model_FeeType::CouponFee, $discount * -1);
        $newItem->addFee(Application_Model_FeeType::ReportFee, $ship->ReportFee);
        $newItem->addFee(Application_Model_FeeType::OperationFee, $serviceFee);
        $newItem->addFee(Application_Model_FeeType::EstimateSum, $shipMoney);
        if ($woodenFee > 0) {
            $newItem->addFee(Application_Model_FeeType::WoodenFee, $woodenFee);
        }

        if ($compressFee > 0) {
            $newItem->addFee(Application_Model_FeeType::VacuumSeviceFee, $compressFee);
        }
        
        if($removalFee>0){
            $newItem->addFee(Application_Model_FeeType::RemovalFee, $removalFee);
        }
        
        if($isRemoteFee && $ship->IsRemoteFee){
            $newItem->addFee(Application_Model_FeeType::RemoteFee, $foRemoteFee);
        }

        if ($premiumFee) {
            $newItem->addFee(Application_Model_FeeType::RatePremiumFee, $premiumFee);
            $newItem->addFee(Application_Model_FeeType::PremiumValue, $premiumValue);
        }

        $reportValue = $this->getSafeParam('reportValue');
        if ($reportValue) {
            $newItem->addFee(Application_Model_FeeType::ReprotValue, $reportValue);
        }

        //添加重量信息
        $newItem->addWeight(Application_Model_WeightType::ProductWeight, $productWeight);
        $newItem->addWeight(Application_Model_WeightType::BagWeight, $bagWeight);
        $newItem->addWeight(Application_Model_WeightType::EstimateWeight, $weight);
        $newItem->addWeight(Application_Model_WeightType::EstimateVolume, $volumeWeight);

        $this->redirect('paying', 'pay', array('type' => Application_Model_PayBill::TYPE_Visiting, 'id' => $visitingItem->id, 'count' => 1));
    }

    public function sfexpressAction() {
        $addressId = $this->getSafeParam("addressid");
        if ($addressId == "" || $addressId == null) {
            return;
        }
        $addressItem = Application_Model_address::load($addressId);
        $prices = Application_Model_ExpressPrice::getPricesByCity($addressItem->city);

        foreach ($prices as $item) {
            $item->SortKey = $item->Express->OrderBy;
        }
        $this->view->prices = Uuch_Util::quickSort($prices, 'SortKey');
        $this->view->cityItem = Application_Model_city::load($addressItem->city);
        $this->disableLayout();
    }

    public function haiwaiAction(){
        $this->appendScript('/js/jquery.min.js'); 
        $this->appendCss('/css/share.css');
        $this->appendCss('/css/haiwai.css');
    }
}
